﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

public partial class NewUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(qman.DataHelp.DataAccess.myConnectionString);
        SqlCommand execProc;
        execProc = new SqlCommand("new_account", conn);
        execProc.CommandType = CommandType.StoredProcedure;

        execProc.Parameters.Add("@user", SqlDbType.VarChar, 100).Value = this.TextBox2.Text;
        execProc.Parameters.Add("@pwd", SqlDbType.VarChar, 25).Value = this.TextBox3.Text;
        execProc.Parameters.Add("@first_name", SqlDbType.VarChar, 60).Value = this.TextBox8.Text;
        execProc.Parameters.Add("@last_name", SqlDbType.VarChar, 60).Value = this.TextBox9.Text;
        execProc.Parameters.Add("@phone", SqlDbType.VarChar, 25).Value = this.TextBox11.Text;
        execProc.Parameters.Add("@email", SqlDbType.VarChar, 100).Value = this.TextBox5.Text;
        execProc.Parameters.Add("@company", SqlDbType.VarChar, 100).Value = this.TextBox10.Text;
        SqlParameter returnValue = new SqlParameter("returnVal", SqlDbType.Int);
        returnValue.Direction = ParameterDirection.ReturnValue;
        execProc.Parameters.Add(returnValue);

        try
        {
            conn.Open();
            execProc.ExecuteNonQuery();
            if (Convert.ToInt32(returnValue.Value) != 2)
                Response.Redirect("~/login.aspx");
            else
            {
                this.TextBox2.Text = "";
                this.Label1.Text = "User name already exists.";
            }
        }
        catch (Exception)
        {
        }
        finally
        {
             conn.Close();
        }
    }
}
